package cqrtplm.listener;

import cn.hutool.extra.spring.SpringUtil;
import com.hustcad.plm.pdm.workflow.annotion.CustomListener;
import com.hustcad.plm.pdm.workflow.model.constant.ProcessConstant;
import cqrtplm.service.RTChgListenerService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;

@Slf4j
@CustomListener(category = "润通", description = "更新表单数据")
public class RTUpdateFormDataListener implements ExecutionListener {


    @Override
    public void notify(DelegateExecution execution) {
        long start = System.currentTimeMillis();
        String workFlowContainerId = execution.getProcessInstanceBusinessKey();
        log.info("----------润通----------开始更新表单数据----workFlowContainerId:{}----->>>", workFlowContainerId);
        if (StringUtils.isBlank(workFlowContainerId)) {
            workFlowContainerId = execution.getVariable(ProcessConstant.WORK_FLOW_CONTAINER_ID).toString();
        }
        RTChgListenerService rtChgListenerService = SpringUtil.getBean(RTChgListenerService.class);
        try {
            rtChgListenerService.updateFormData(workFlowContainerId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        log.info("----------更新表单数据：{}---->>>", System.currentTimeMillis() - start);
    }

}
